473,418 Members | 2,070 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

unicode/ascii codes in javascript


Folks,

I have two related questions:

1. I have seen unicode being mentioned in my javascript pocket book - is
this the same as ascii codes? I think not though I'm not sure and I
can't find any examples...

2. How do I read/set a string to an unprintable code? For example, how
can I set the variable a to equal the equivalent of ascii code 7 or 8 or
whatever...

Why? I am working on an application which allows the user to enter in
multiple names - I want to store these multiple names in a hidden text
box using a none-printable character as a field seperate for each input
text field value. I know 100% that my keyboard entries will be
ascii/qwerty.

Can someone steer me in the right direction?

randelld
Jul 23 '05 #1
13 9010
> 1. I have seen unicode being mentioned in my javascript pocket book - is
this the same as ascii codes? I think not though I'm not sure and I
can't find any examples...
ASCII is a subset of Unicode. Buy a better book.
2. How do I read/set a string to an unprintable code? For example, how
can I set the variable a to equal the equivalent of ascii code 7 or 8 or
whatever...

Why? I am working on an application which allows the user to enter in
multiple names - I want to store these multiple names in a hidden text
box using a none-printable character as a field seperate for each input
text field value. I know 100% that my keyboard entries will be
ascii/qwerty.

Can someone steer me in the right direction?


Yeah. Don't do it. No security is obtained from such ridiculous methods.
The list of names must be kept on the server, never in the client.

http://www.crockford.com/javascript/survey.html
Jul 23 '05 #2
Douglas Crockford wrote:
1. I have seen unicode being mentioned in my javascript pocket book -
is this the same as ascii codes? I think not though I'm not sure and I
can't find any examples...

ASCII is a subset of Unicode. Buy a better book.
2. How do I read/set a string to an unprintable code? For example,
how can I set the variable a to equal the equivalent of ascii code 7
or 8 or whatever...

Why? I am working on an application which allows the user to enter in
multiple names - I want to store these multiple names in a hidden text
box using a none-printable character as a field seperate for each
input text field value. I know 100% that my keyboard entries will be
ascii/qwerty.

Can someone steer me in the right direction?

Yeah. Don't do it. No security is obtained from such ridiculous methods.
The list of names must be kept on the server, never in the client.

http://www.crockford.com/javascript/survey.html

Thanks - I am aware of security concerns - but security is not a problem
for me as I'm working on a small intranet based application - in
addition, I will sanitize my input using PHP...

Thus - canyou answer my second question? How can I sest a variable to be
the equivalent of ascii code 7 or 8 or whatever - I believe I can read a
string, and find the unicode values of each character, but I don't know
what function I can use for the reverse of this process.

cheers
randelld
Jul 23 '05 #3
Douglas Crockford wrote:
1. I have seen unicode being mentioned in my javascript pocket book -
is this the same as ascii codes? I think not though I'm not sure and I
can't find any examples...

ASCII is a subset of Unicode. Buy a better book.
2. How do I read/set a string to an unprintable code? For example,
how can I set the variable a to equal the equivalent of ascii code 7
or 8 or whatever...

Why? I am working on an application which allows the user to enter in
multiple names - I want to store these multiple names in a hidden text
box using a none-printable character as a field seperate for each
input text field value. I know 100% that my keyboard entries will be
ascii/qwerty.

Can someone steer me in the right direction?

Yeah. Don't do it. No security is obtained from such ridiculous methods.
The list of names must be kept on the server, never in the client.

http://www.crockford.com/javascript/survey.html


Ah! I've just realised that you have have also mis-understood my second
question... I do not want to have the names written as part of the
javascript... this I would agree, would be silly...

I have a form - it has INPUT tags asking for firstname and lastname.

I also have a hidden input box.

When the user enters a firstname and lastname, I have an onClick
function which takes the input from the firstname/lastname box, and
writes it to the hidden input box. I want this so as the client can
enter several names all at once without having to post the form each
time. Once they have finished inputing the names, the user clicks on a
submit button which then passes the hidden input box to my php based server.

In order for my php script to read the input, I want the hidden text box
to have a fixed format - thus, for example, firstname is always followed
by ascii character 8 followed by lastname. I can then easily unpack
this long string on the server side.

Thus - can you tell me how I can set a variable called fs equal to ascii
character 8? Or even unicode character 8? (It doesn't have to be 8 - but
something not readily available from qwerty keyboard input)

Thanks
Randell D.
Jul 23 '05 #4
Randell D. wrote:

<--snip-->
Thus - can you tell me how I can set a variable called fs equal to ascii
character 8? Or even unicode character 8? (It doesn't have to be 8 - but
something not readily available from qwerty keyboard input)


var fs="ß";

Copy and paste as desired. Unless someone you know spells a name with a
B like that. Then, you could use :

var fs="Þ";

or something similar.

It doesn't have to be "non-printable", it only has to be unique.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #5
Randy Webb wrote:
Randell D. wrote:

<--snip-->
Thus - can you tell me how I can set a variable called fs equal to
ascii character 8? Or even unicode character 8? (It doesn't have to be
8 - but something not readily available from qwerty keyboard input)

var fs="ß";

Copy and paste as desired. Unless someone you know spells a name with a
B like that. Then, you could use :

var fs="Þ";

or something similar.

It doesn't have to be "non-printable", it only has to be unique.


Yep - I agree that it only has to be unique and I'm grateful for your
suggested solution (which I will use) however I guess there is no method
available in javascript to do what I want to do... true? (Just for a
curiosity/js-educational point of view).

thanks
randelld
Jul 23 '05 #6
Randell D. wrote:
Randy Webb wrote:
Randell D. wrote:

<--snip-->
Thus - can you tell me how I can set a variable called fs equal to
ascii character 8? Or even unicode character 8? (It doesn't have to
be 8 - but something not readily available from qwerty keyboard input)


var fs="ß";

Copy and paste as desired. Unless someone you know spells a name with
a B like that. Then, you could use :

var fs="Þ";

or something similar.

It doesn't have to be "non-printable", it only has to be unique.


Yep - I agree that it only has to be unique and I'm grateful for your
suggested solution (which I will use) however I guess there is no method
available in javascript to do what I want to do... true? (Just for a
curiosity/js-educational point of view).


Never really tried but instincts tells me it should be able to, provided
you can get the Unicode character sequence for it.

A while back I wrote a script that I needed a delimiter for much as you
need one and settled on the following:

var myVar = "ßàßÝÞ±º¹²³®©";

And unless someone every happened to type that particular sequence then
my app is pretty secure :)

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #7
Randy Webb wrote:
Randell D. wrote:
Randy Webb wrote:
Randell D. wrote:

<--snip-->

Thus - can you tell me how I can set a variable called fs equal to
ascii character 8? Or even unicode character 8? (It doesn't have to
be 8 - but something not readily available from qwerty keyboard input)


var fs="ß";

Copy and paste as desired. Unless someone you know spells a name with
a B like that. Then, you could use :

var fs="Þ";

or something similar.

It doesn't have to be "non-printable", it only has to be unique.


Yep - I agree that it only has to be unique and I'm grateful for your
suggested solution (which I will use) however I guess there is no
method available in javascript to do what I want to do... true? (Just
for a curiosity/js-educational point of view).

Never really tried but instincts tells me it should be able to, provided
you can get the Unicode character sequence for it.

A while back I wrote a script that I needed a delimiter for much as you
need one and settled on the following:

var myVar = "ßàßÝÞ±º¹²³®©";

And unless someone every happened to type that particular sequence then
my app is pretty secure :)

Thanks again...
randelld
Jul 23 '05 #8
In article <ZWONd.315378$Xk.22008@pd7tw3no>,
"Randell D." <re******************************@fiprojects.moc > wrote:
2. How do I read/set a string to an unprintable code? For example, how
can I set the variable a to equal the equivalent of ascii code 7 or 8 or
whatever...


This may help.

Robert

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Saving stats</title>
<base href="http://spaceplace.jpl.nasa.gov/en/_images/">
<script type="text/javascript">

nullCharacter = "\0"
backSpace = "\b"

orUnicode = "\u0000"
oldChar = "\x00"

alert ( "nullCharacter.length = " + nullCharacter.length + " " +
escape(nullCharacter) +
"\n" +
" backSpace = '" + backSpace + "'" + " " +
escape(backSpace) +
"\n" +
" orUnicode.length = " + orUnicode.length + " " +
escape(orUnicode) +
"\n" +
" oldChar.length = " + oldChar.length + " " +
escape(oldChar))

</script>
</head>
<body >
<p> How is that.</>
</body>
</html>
Jul 23 '05 #9
Robert wrote:
In article <ZWONd.315378$Xk.22008@pd7tw3no>,
"Randell D." <re******************************@fiprojects.moc > wrote:

2. How do I read/set a string to an unprintable code? For example, how
can I set the variable a to equal the equivalent of ascii code 7 or 8 or
whatever...

This may help.

Robert

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Saving stats</title>
<base href="http://spaceplace.jpl.nasa.gov/en/_images/">
<script type="text/javascript">

nullCharacter = "\0"
backSpace = "\b"

orUnicode = "\u0000"
oldChar = "\x00"

alert ( "nullCharacter.length = " + nullCharacter.length + " " +
escape(nullCharacter) +
"\n" +
" backSpace = '" + backSpace + "'" + " " +
escape(backSpace) +
"\n" +
" orUnicode.length = " + orUnicode.length + " " +
escape(orUnicode) +
"\n" +
" oldChar.length = " + oldChar.length + " " +
escape(oldChar))

</script>
</head>
<body >
<p> How is that.</>
</body>
</html>


Interesting... I've saved that for reference... it took me a second, but
I can understand what you've done...

Cheers
Randell D.
Jul 23 '05 #10
Randy Webb wrote:
Randell D. wrote:
Randy Webb wrote:
Randell D. wrote:

<--snip-->

Thus - can you tell me how I can set a variable called fs equal to
ascii character 8? Or even unicode character 8? (It doesn't have to
be 8 - but something not readily available from qwerty keyboard input)


var fs="ß";

Copy and paste as desired. Unless someone you know spells a name with
a B like that. Then, you could use :

var fs="Þ";

or something similar.

It doesn't have to be "non-printable", it only has to be unique.


Yep - I agree that it only has to be unique and I'm grateful for your
suggested solution (which I will use) however I guess there is no
method available in javascript to do what I want to do... true? (Just
for a curiosity/js-educational point of view).

Never really tried but instincts tells me it should be able to, provided
you can get the Unicode character sequence for it.

A while back I wrote a script that I needed a delimiter for much as you
need one and settled on the following:

var myVar = "ßàßÝÞ±º¹²³®©";

And unless someone every happened to type that particular sequence then
my app is pretty secure :)

Randy,

I have another post,with subject line 'Re: Odd problem: Data from hidden
field is not sent to server...' that you might be able to help with (if
you don't mind). Without duplicating the entire post, basically, *the
value* my box receives from the result of a javascript function does not
get sent to the server - yet if I manually complete the same field, the
manually entered data does get sent to the server.

I'm wondering if you had any similar problem as you mentioned you've
done something similar to me at some point in the past...

If you can help please reply to my other post as it might well help
others at some pointin the future.

Cheers
randelld
Jul 23 '05 #11


Randell D. wrote:

2. How do I read/set a string to an unprintable code? For example, how
can I set the variable a to equal the equivalent of ascii code 7 or 8 or
whatever...


There is a method
String.fromCharCode
which takes one ore more numbers as its arguments and creates a string
with as many characters as arguments where the characters are taken from
the numbers interpreted as Unicode code points, thus
var s = String.fromCharCode(65, 66, 67);
makes s have the value 'ABC' or
var s = String.fromCharCode(8364);
the value '€'.

Check <http://www.unicode.org/> for Unicode code charts.

The other way round is
string.charCodeAt(characterIndex)
e.g. with var s = String.fromCharCode(8364); the expression
s.charCodeAt(0) yields the number 8364.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #12
JRS: In article <Fc********************@comcast.com>, dated Mon, 7 Feb
2005 18:01:06, seen in news:comp.lang.javascript, Randy Webb
<Hi************@aol.com> posted :
Randell D. wrote:

<--snip-->
Thus - can you tell me how I can set a variable called fs equal to ascii
character 8? Or even unicode character 8? (It doesn't have to be 8 - but
something not readily available from qwerty keyboard input)

Why not with String.fromCharCode() ?

S = String.fromCharCode(0x62b) shows me three peas falling into a wok.

-
comp.lang.javascript FAQ - http://jibbering.com/faq


If that's boilerplate, how about adding "& newsgroup weekly"?

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #13
Dr John Stockton wrote:
JRS: In article <Fc********************@comcast.com>, dated Mon, 7 Feb
2005 18:01:06, seen in news:comp.lang.javascript, Randy Webb
<Hi************@aol.com> posted :


<--snip-->
comp.lang.javascript FAQ - http://jibbering.com/faq

If that's boilerplate, how about adding "& newsgroup weekly"?


Semi-boilerplate but close enough that I changed it.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: nico | last post by:
In my python scripts, I use a lot of accented characters as I work in french. In order to do this, I put the line # -*- coding: UTF-8 -*- at the beginning of the script file. Then, when I need...
6
by: Spamtrap | last post by:
I only work in Perl occasionaly, and have been searching for a solution for a conversion, and everything I found seems much too complex. All I need to do is take a simple text file and copy...
15
by: Craig Wagner | last post by:
I have a situation where I have a series of character codes stored in the database. In some cases they are the ASCII value of the character, in other cases they are the > 127 character code value...
2
by: Gidi | last post by:
Hi, I'm writing a C# win application program, and i need to transfer my hebrew letters from unicode to ascii, now if i use the ascii encoding it writes me ??? instead of the hebrew letter i've...
24
by: ChaosKCW | last post by:
Hi I am reading from an oracle database using cx_Oracle. I am writing to a SQLite database using apsw. The oracle database is returning utf-8 characters for euopean item names, ie special...
14
by: abhi147 | last post by:
Hi , I want to convert an array of bytes like : {79,104,-37,-66,24,123,30,-26,-99,-8,80,-38,19,14,-127,-3} into Unicode character with ISO-8859-1 standard. Can anyone help me .. how should...
7
by: JTree | last post by:
Hi,all I encountered a problem when using unicode() function to fetch a webpage, I don't know why this happenned. My codes and error messages are: Code: #!/usr/bin/python #Filename: test.py...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
7
by: 7stud | last post by:
Based on this example and the error: ----- u_str = u"abc\u9999" print u_str UnicodeEncodeError: 'ascii' codec can't encode character u'\u9999' in position 3: ordinal not in range(128) ------
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.